﻿Public Class FrmAlquiler
    Private Sub btnBuscarSocio_Click(sender As System.Object, e As System.EventArgs) Handles btnBuscarSocio.Click
        If My.Forms.FrmBusquedaSocio.ShowDialog() = Windows.Forms.DialogResult.OK Then
            txtSocio.Text = My.Forms.FrmBusquedaSocio.DNISocio
        End If
    End Sub

    Private Sub btnBuscarPelicula_Click(sender As System.Object, e As System.EventArgs) Handles btnBuscarPelicula.Click
        If My.Forms.FrmBusquedaPelicula.ShowDialog() = Windows.Forms.DialogResult.OK Then
            txtPelicula.Text = My.Forms.FrmBusquedaPelicula.PeliculaCodigoDeBarras
        End If
    End Sub

    Private Sub btnAceptar_Click(sender As System.Object, e As System.EventArgs) Handles btnAceptar.Click
        Dim logicaAlquiler As New LogicaAlquiler()
        Try
            logicaAlquiler.AlquilarPelicula(txtPelicula.Text, txtSocio.Text)
            MessageBox.Show("El alquiler ha sido exitoso")
            Me.Close()
        Catch ex As PeliculaNoExisteException
            errorProvider.SetError(panelPelicula, "No existe la película")
        Catch ex As SocioNoExisteException
            errorProvider.SetError(panelSocio, "No existe el socio")
        Catch ex As PeliculaSinStockException
            MessageBox.Show("La película no tiene stock")
        End Try
    End Sub

    Private Sub btnCancelar_Click(sender As System.Object, e As System.EventArgs) Handles btnCancelar.Click
        Me.Close()
    End Sub

    Private Sub txtPelicula_TextChanged(sender As Object, e As System.EventArgs) Handles txtPelicula.TextChanged
        errorProvider.SetError(panelPelicula, "")
    End Sub

    Private Sub txtSocio_TextChanged(sender As Object, e As System.EventArgs) Handles txtSocio.TextChanged
        errorProvider.SetError(panelSocio, "")
    End Sub
End Class